﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Interactivity;



namespace for7raid.Control
{
    public class ScrollIntoViewBehavior : Behavior<ListBox>
    {
        public ScrollIntoViewBehavior()
        {
           
        }

        protected override void OnAttached()
        {
            base.OnAttached();
            AssociatedObject.SelectionChanged += new SelectionChangedEventHandler(AssociatedObject_SelectionChanged);
            // Insert code that you would want run when the Behavior is attached to an object.
        }

        void AssociatedObject_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            AssociatedObject.ScrollIntoView(AssociatedObject.SelectedItem);

            if (e.RemovedItems != null)
                foreach (DependencyObject o in e.RemovedItems)
                    vkPlayer.PlayerViewModel.SetSelected(o, false);

            if (e.AddedItems != null)
                foreach (DependencyObject o in e.AddedItems)
                    vkPlayer.PlayerViewModel.SetSelected(o, true);

        }

        protected override void OnDetaching()
        {
            base.OnDetaching();

            // Insert code that you would want run when the Behavior is removed from an object.
        }

       
    }
}